home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc Source Code / Utilities / PlfmFil2.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-22  |  2.5 KB  |  117 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        PlfmFil2.cpp
  3.  
  4.     Contains:    Implementation of PlatformFile::HasFileSpecChanged
  5.                 and PlatformFile::IsInTrash.
  6.  
  7.     Owned by:    Jens Alfke
  8.     Written by:    Jens Alfke, based on code by Mark Linton and Jim Luther
  9.  
  10.     Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  11.  
  12. */
  13.  
  14.  
  15. #ifndef _PLFMFILE_
  16. #include "PlfmFile.h"
  17. #endif
  18.  
  19. #ifndef __EVENTS__
  20. #include <Events.h>
  21. #endif
  22.  
  23. #ifndef __FILES__
  24. #include <Files.h>
  25. #endif
  26.  
  27. #ifndef __FOLDERS__
  28. #include <Folders.h>
  29. #endif
  30.  
  31. #ifndef _ODDEBUG_
  32. #include "ODDebug.h"
  33. #endif
  34.  
  35. #ifndef __EXCEPT__
  36. #include "Except.h"
  37. #endif
  38.  
  39.  
  40. const ODULong    kMinCheckInterval = 1 * 60;        // Never check more than once a second
  41.  
  42. const long        kRootDir          = 2;            // Directory ID of volume root
  43.  
  44.  
  45. static OSErr    GetParentID(short vRefNum,
  46.                             long dirID,
  47.                             StringPtr name,
  48.                             long *parID);
  49. static OSErr    GetDirName(short vRefNum,
  50.                            long dirID,
  51.                            StringPtr name);
  52.  
  53.  
  54. ODBoolean
  55. PlatformFile::IsInTrash( )
  56. {
  57.     ODFileSpec fss = this->GetFileSpec();
  58.     ODSShort foundVol;
  59.     ODSLong trashDir, netTrashDir;
  60.     OSErr err= FindFolder(fss.vRefNum,kTrashFolderType, kODTrue, &foundVol,&trashDir);
  61.     if( err )
  62.         trashDir = 0;
  63.     err= FindFolder(fss.vRefNum,kWhereToEmptyTrashFolderType, kODTrue, &foundVol,&netTrashDir);
  64.     if( err )
  65.         netTrashDir = 0;
  66.     
  67.     while( fss.parID != kRootDir ) {
  68.         if( fss.parID == trashDir || fss.parID == netTrashDir )
  69.             return kODTrue;
  70.         long parent;
  71.         if( GetParentID(fss.vRefNum,fss.parID,NULL, &parent) != noErr )    // Get next parent
  72.             break;
  73.         if( GetDirName(fss.vRefNum,fss.parID, fss.name) != noErr )        // Get name of current parent
  74.             break;
  75.         fss.parID = parent;
  76.     }
  77.     return kODFalse;
  78. }
  79.  
  80.  
  81.  
  82. /*============================================================================================*/
  83. //    SWIPED FROM MOREFILES 1.2.1 (DTS)
  84. /*============================================================================================*/
  85.  
  86.  
  87. static    OSErr    GetParentID(short vRefNum,
  88.                             long dirID,
  89.                             StringPtr name,
  90.                             long *parID)
  91. {
  92.     CInfoPBRec pb;
  93.     OSErr error;
  94.     
  95.     pb.hFileInfo.ioNamePtr = name;
  96.     pb.hFileInfo.ioVRefNum = vRefNum;
  97.     pb.hFileInfo.ioDirID = dirID;
  98.     pb.hFileInfo.ioFDirIndex = name ?0 :-1;
  99.     error = PBGetCatInfoSync(&pb);
  100.     *parID = pb.hFileInfo.ioFlParID;
  101.     return ( error );
  102. }
  103.  
  104.  
  105. static    OSErr    GetDirName(short vRefNum,
  106.                            long dirID,
  107.                            StringPtr name)
  108.         {
  109.     CInfoPBRec pb;
  110.  
  111.     pb.hFileInfo.ioNamePtr = name;
  112.     pb.hFileInfo.ioVRefNum = vRefNum;
  113.     pb.hFileInfo.ioDirID = dirID;
  114.     pb.hFileInfo.ioFDirIndex = -1;    /* get information about ioDirID */
  115.     return ( PBGetCatInfoSync(&pb) );
  116. }
  117.